<?php

class Modules_Gallery extends Module {

	public $title = "Галереи";
	public $name = "gallery";

	protected function _actionproperties(Blocks $block) {
		
	}

	public function actions() {
		
	}

	public function mainActions() {
		
	}

	public static function subMenu() {
		return array(
			array(
				'url' => '/admin.php?module=gallery&action=gallery',
				'title' => 'Галереи',
				'icon' => '/tpl/admin/images/inbox-image.png',
			),
		);
	}

	public function adminActionIndex() {
		return $this->adminActionGallery();
	}
	
	public function adminActionGallery(){
		$galleries = Doctrine_Query::create()
				->from('Gallery')
				->execute();
		$users = Doctrine_Query::create()
				->from('Users')
				->execute();
		$_gallery = new Gallery();
		
		return $this->renderTpl('gallery_list.html', array(
			'_gallery' => $_gallery,
			'galleries' => $galleries,
			'users' => $users,
		));
	}
	
	public function adminActionGallery_save(){
		$data = isset($_REQUEST['gallery']) ? $_REQUEST['gallery'] : array();
		$data['id'] = (int)$data['id'];
		
		$gallery = $data['id'] ? Doctrine_Core::getTable('Gallery')->find($data['id']) : new Gallery();
		unset($data['id']);
		
		$gallery->fromArray($data);
		$gallery->save();
		
		Request::redirect(-1);
	}

}